<?php
/* All functions are inherited from  functions.php located in 
	the parent theme \wp-content\plugins\buddypress\bp-themes\bp-default.
	
	Add functions in here specific to the Twyne child theme
*/


/*register side bars
------------------------------------------------------*/
add_action( 'widgets_init', 'my_register_sidebars' ); //adds action hook so code isn't just dropped into functions.php
function my_register_sidebars() {

	register_sidebar( array(
		'name'          => 'Location Main Page sidebar',
		'id'            => 'location-main-page',
		'description'   => __( 'The Location Main Page sidebar', 'buddypress' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<h3 class="widgettitle">',
		'after_title'   => '</h3>'
	) );
	register_sidebar( array(
		'name'          => 'Front Page sidebar',
		'id'            => 'front-page',
		'description'   => __( 'The Front Page sidebar', 'buddypress' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<h3 class="widgettitle">',
		'after_title'   => '</h3>'
	) );
	register_sidebar( array(
		'name'          => 'Empty sidebar',
		'id'            => 'empty',
		'description'   => __( 'A sidebar with the login prompt but no widgets', 'buddypress' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<h3 class="widgettitle">',
		'after_title'   => '</h3>'
	) );
	register_sidebar( array(
		'name'          => 'Profile sidebar',
		'id'            => 'profile',
		'description'   => __( 'A sidebar that appears when viewing a member profile', 'buddypress' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<h3 class="widgettitle">',
		'after_title'   => '</h3>'
	) );
	register_sidebar( array(
		'name'          => 'Invisible Widget Area',
		'id'            => 'invisible',
		'description'   => __( 'Invisible sidebar intended for the "Tabbed Widgets" plugin', 'buddypress' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<h3 class="widgettitle">',
		'after_title'   => '</h3>'
	) );
	register_sidebar( array(
		'name'          => 'Group sidebar',
		'id'            => 'groups',
		'description'   => __( 'Sidebar for all Groups', 'buddypress' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<h3 class="widgettitle">',
		'after_title'   => '</h3>'
	) );
	/* Repeat register_sidebar() code for additional sidebars. */
}

 /* Create SQL query to find all cities and corresponding
 slugs in the state sent through the AJAX call. Prepare and
 return HTML code to create cities dropdown menu.
------------------------------------------------------*/
add_action('wp_ajax_popCities', 'populate_Cities');
add_action('wp_ajax_nopriv_popCities', 'populate_Cities');
function populate_Cities() {
	global $wpdb;
	
	// Get the 'state' data items from the _POST Ajax call
	$state = $_POST["state"];    

	// Query the database for all cities in specified state. 
	// Return HTML for cities dropdown
	$cities=$wpdb->get_results($wpdb->prepare("
	SELECT name,slug
	FROM wp_bp_groups
	WHERE status='public' AND description=%s
	ORDER BY name",$state));	
		$temp= "\nSelect a city: <select name='cities'>
							<option value='bad'> Choose a city</option>\n";
        foreach ($cities as $city) {
            $temp=$temp."<option value={$city->slug}>{$city->name}</option>\n";
        };
		$temp=$temp."</select>\n";
		echo $temp;
	
		
	die();

}
 /*---------------------------------------------------
 Find and display MATCHING percentatages
------------------------------------------------------*/
add_action('wp_ajax_findMatch', 'find_Matches');
add_action('wp_ajax_nopriv_findMatch', 'find_Matches');
function find_Matches() {
	global $wpdb;
	$gid = $_POST["group"];
	$userid = $_POST["userid"];
	$my_ans = $wpdb->get_row("SELECT *
							FROM wp_twyne_matching
							WHERE $userid = user_id",ARRAY_N );
	$coed = $my_ans[1];
	$sex = $wpdb->get_var($wpdb->prepare("SELECT value
										  FROM wp_bp_xprofile_data
										  WHERE user_id = $userid AND field_id = '3'"));
	//if not coed
	if($coed == '0'){
		if($sex == 'Male'){
		echo $male;
		$users=$wpdb->get_col($wpdb->prepare("SELECT Distinct wp_bp_groups_members.user_id
										  FROM wp_bp_xprofile_data,wp_bp_groups_members,wp_twyne_matching
										  WHERE wp_bp_xprofile_data.value = 'Male'
										  AND wp_bp_xprofile_data.field_id = '3'
										  AND wp_bp_groups_members.group_id = $gid
										  AND wp_bp_groups_members.user_id  <> $userid
										  AND wp_bp_groups_members.user_id  <> '1'
										  AND wp_twyne_matching.user_id = wp_bp_groups_members.user_id
										  AND wp_twyne_matching.user_id = wp_bp_xprofile_data.user_id
										  ORDER BY wp_bp_xprofile_data.user_id"));
		} else{
		$users=$wpdb->get_col($wpdb->prepare("SELECT Distinct wp_bp_groups_members.user_id
										  FROM wp_bp_xprofile_data,wp_bp_groups_members,wp_twyne_matching
										  WHERE wp_bp_xprofile_data.value = 'Female' 
										  AND wp_bp_xprofile_data.field_id = '3'
										  AND wp_bp_groups_members.group_id = $gid
										  AND wp_bp_groups_members.user_id  <> $userid
										  AND wp_bp_groups_members.user_id  <> '1'
										  AND wp_twyne_matching.user_id = wp_bp_groups_members.user_id
										  AND wp_twyne_matching.user_id = wp_bp_xprofile_data.user_id
										  ORDER BY wp_bp_xprofile_data.user_id"));	
		}
	}else{
		if($sex == 'Male'){
		$users=$wpdb->get_col($wpdb->prepare("SELECT Distinct wp_bp_groups_members.user_id
										  FROM wp_bp_xprofile_data,wp_bp_groups_members,wp_twyne_matching
										  WHERE ((wp_bp_xprofile_data.value = 'Female'
										  AND wp_twyne_matching.q1 = '1') 
										  OR wp_bp_xprofile_data.value = 'Male')
										  AND wp_bp_xprofile_data.field_id = '3'
										  AND wp_bp_groups_members.group_id = $gid
										  AND wp_bp_groups_members.user_id  <> $userid
										  AND wp_bp_groups_members.user_id  <> '1'
										  AND wp_twyne_matching.user_id = wp_bp_groups_members.user_id
										  AND wp_twyne_matching.user_id = wp_bp_xprofile_data.user_id
										  ORDER BY wp_bp_xprofile_data.user_id"));
		} else{
		$users=$wpdb->get_col($wpdb->prepare("SELECT Distinct wp_bp_groups_members.user_id
										  FROM wp_bp_xprofile_data,wp_bp_groups_members,wp_twyne_matching
										  WHERE ((wp_bp_xprofile_data.value = 'Male'
										  AND wp_twyne_matching.q1 = '1') 
										  OR wp_bp_xprofile_data.value = 'Female')										  
										  AND wp_bp_xprofile_data.field_id = '3'
										  AND wp_bp_groups_members.group_id = $gid
										  AND wp_bp_groups_members.user_id  <> $userid
										  AND wp_bp_groups_members.user_id  <> '1'
										  AND wp_twyne_matching.user_id = wp_bp_groups_members.user_id
										  AND wp_twyne_matching.user_id = wp_bp_xprofile_data.user_id
										  ORDER BY wp_bp_xprofile_data.user_id"));	
		}
	/*	
	$users=$wpdb->get_col($wpdb->prepare("SELECT Distinct wp_bp_groups_members.user_id
										  FROM wp_bp_groups_members,wp_twyne_matching
										  WHERE wp_bp_groups_members.group_id = $gid 
										  AND wp_bp_groups_members.user_id  <> $userid
										  AND wp_bp_groups_members.user_id  <> '1'
										  AND wp_twyne_matching.q1 = '1'
										  AND wp_twyne_matching.user_id = wp_bp_groups_members.user_id
										  ORDER BY wp_bp_groups_members.user_id"));
	*/
	}
	$count = count($users);
	$fullname = array();
	//fullname array
	if(empty($users)){echo 'Sorry, No members in this group have completed the Matching Questionaire';}
	else{
	for($i=0; $i<$count; $i++){
		$fname= $wpdb->get_var($wpdb->prepare("SELECT meta_value
										  FROM wp_usermeta
										  WHERE user_id = $users[$i] AND meta_key = 'first_name'
										  ORDER BY user_id"));
		$lname= $wpdb->get_var($wpdb->prepare("SELECT meta_value
										  FROM wp_usermeta
										  WHERE user_id = $users[$i] AND meta_key = 'last_name'
										  ORDER BY user_id"));
		$fullname[$i] = $fname . " " . $lname;
	}

	$percent = array();
	//calculate difference
	for ($i=0; $i<$count; $i++){
		$diff = 0;
		$fr_ans = $wpdb->get_row("SELECT *
							FROM wp_twyne_matching
							WHERE $users[$i] = user_id",ARRAY_N );
		for ($j=2; $j<= 27; $j++){
			$diff = $diff + abs($my_ans[$j] - $fr_ans[$j]);
		}
		$percent[$i] = 100  - $diff;
	}
	//sort by percent
    for ($i=0; $i<$count; $i++) {
        for ($j=0; $j<$count-1-$i; $j++) {
            if ($percent[$j] < $percent[$j+1]) {
                $tmp = $fullname[$j+1];
				$tmp2 = $percent[$j+1];
				$tmp3 = $users[$j+1];
				$fullname[$j+1] = $fullname[$j];
				$percent[$j+1] = $percent[$j];
				$users[$j+1] = $users[$j];
				$fullname[$j] = $tmp;
				$percent[$j] = $tmp2;
				$users[$j] = $tmp3;
            }
        }
    }

	echo '<table>';
	echo "<td align = 'left'><u>Group Member</u></td>";
	echo "<td align = 'right'><u>Percent Match</u></td>";
	for ($i=0; $i<$count; $i++) {
		$id = $users[$i];
		$url = bp_core_get_user_domain($id);
		$url_name = $fullname[$i];
		echo '<tr>';
		echo  "<td align = 'left'><a href='$url'>$url_name</a></td>";
		echo  "<td align = 'right'>$percent[$i] %</td>";
		echo '</tr>';
	}
	echo '</table>';
	}
	die();
}
 /*---------------------------------------------------
 SUBMIT/UPDATE MATCHING QUESTIONAIRE
------------------------------------------------------*/
add_action('wp_ajax_setMatch', 'set_Matches');
add_action('wp_ajax_nopriv_setMatch', 'set_Matches');
function set_Matches() {
	global $wpdb;
	$questArray = $_POST["qArray"];
	$userid = $_POST["userid"];
	$check = $wpdb->get_var("SELECT COUNT(*)
							FROM wp_twyne_matching
							WHERE $userid = user_id");
	echo $check;
	if($check == 0){
	$wpdb->insert( 
	'wp_twyne_matching', 
	array( 
		'user_id' => $userid, 
		'q1' => $questArray[0],
		'q2' => $questArray[1],
		'q3' => $questArray[2],
		'q4' => $questArray[3],
		'q5' => $questArray[4],
		'q6' => $questArray[5],
		'q7' => $questArray[6],
		'q8' => $questArray[7],
		'q9' => $questArray[8],
		'q10' => $questArray[9],
		'q11' => $questArray[10],
		'q12' => $questArray[11],
		'q13' => $questArray[12],
		'q14' => $questArray[13],
		'q15' => $questArray[14],
		'q16' => $questArray[15],
		'q17' => $questArray[16],
		'q18' => $questArray[17],
		'q19' => $questArray[18],
		'q20' => $questArray[19],
		'q21' => $questArray[20],
		'q22' => $questArray[21],
		'q23' => $questArray[22],
		'q24' => $questArray[23],
		'q25' => $questArray[24],
		'q26' => $questArray[25],
	), 
	array( 
		'%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d', 
		'%d','%d','%d','%d','%d','%d', '%d','%d','%d','%d','%d','%d','%d',
	) 
);
}else{
$wpdb->update( 
	'wp_twyne_matching', 
	array( 
		'user_id' => $userid, 
		'q1' => $questArray[0],
		'q2' => $questArray[1],
		'q3' => $questArray[2],
		'q4' => $questArray[3],
		'q5' => $questArray[4],
		'q6' => $questArray[5],
		'q7' => $questArray[6],
		'q8' => $questArray[7],
		'q9' => $questArray[8],
		'q10' => $questArray[9],
		'q11' => $questArray[10],
		'q12' => $questArray[11],
		'q13' => $questArray[12],
		'q14' => $questArray[13],
		'q15' => $questArray[14],
		'q16' => $questArray[15],
		'q17' => $questArray[16],
		'q18' => $questArray[17],
		'q19' => $questArray[18],
		'q20' => $questArray[19],
		'q21' => $questArray[20],
		'q22' => $questArray[21],
		'q23' => $questArray[22],
		'q24' => $questArray[23],
		'q25' => $questArray[24],
		'q26' => $questArray[25],
	), 
	array('user_id' => $userid),
	array( 
		'%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d', 
		'%d','%d','%d','%d','%d','%d', '%d','%d','%d','%d','%d','%d','%d',
	) 
);

}
	
	die();
}

 /*---------------------------------------------------
 DELETE MATCHING ANSWERS
------------------------------------------------------*/
add_action('wp_ajax_removeMatch', 'delete_Match');
add_action('wp_ajax_nopriv_removeMatch', 'delete_Matches');
function delete_Match() {
	global $wpdb;
	$userid = $_POST["uid"]; 
	$wpdb->query( 
			$wpdb->prepare( 
		"
		 DELETE FROM wp_twyne_matching
				WHERE user_id = $userid;
		"	
			)
		);
		
		die();
}
 /* Create SQL query to check if the Group Code passed in the
  * parameter is present in the database. If it is present,
  * check if the email address passed as the second parameter 
  * is assigned to the Group Code. Also check for the Nonce 
  * from the Ajax request.
------------------------------------------------------*/
add_action('wp_ajax_verify_group_code', 'check_group_code');
add_action('wp_ajax_nopriv_verify_group_code', 'check_group_code');
function check_group_code() {
	global $wpdb;
	
	// Get the 'code' and 'email' and 'postCommentNonce' data items from the _POST Ajax call
	$code = $_POST["code"];
	$email = $_POST["email"];
	$nonce = $_POST['postCommentNonce'];
    // check to see if the submitted nonce matches with the generated nonce we created earlier
    if ( ! wp_verify_nonce( $nonce, 'myajax-post-comment-nonce' ) )
        die ( 'Busted!');

	// Query the database verifying the Group Code is present and has the correct email registered with it. 
	// Return the Group Slug
	$slug = $wpdb->get_var($wpdb->prepare("SELECT slug FROM {$wpdb->prefix}twyne_group_code_assgn WHERE group_code = %s", $code));	
	
	if ( empty( $slug ) )
		echo "failed";
	else {
		$url = bloginfo('url')."/groups/".$slug;  //Create the group url
		echo $url;
	}
		
	die();

}

/* Generate a new row in table wp_twyne_group_code_assgn after a group gets created, generating a new Group Code. 
 * Accepts 3 args: 1.) The newly created group id; 2.) A member object containing details of the user
 * who created the group; 3.) A group object with attributes of the newly created group.
 * For further details see do_action( 'groups_create_group' ) in the core file : buddypress/bp-groups/bp-groups-functions.php.
--------------------------------------------------------------------------------------------------*/
add_action('groups_create_group', 'generate_row_group_code_assgn', 10, 3);  //priority=10, args=3
function generate_row_group_code_assgn( $group_id, $member, $group){
	global $wpdb;
	
	$id = $group_id;
	$slug = $group->slug;
	
	//once you have the id and slug, generate a group code and insert a new row in wp_twyne_group_code_assgn
	$group_code = wp_generate_password(20, false);  // Generate a random 10 digit code
	$wpdb->insert(
			'wp_twyne_group_code_assgn',
			array(
				'group_id' => $id,
				'group_code' => $group_code,
				'state' => $_POST['states'],  
				'city' => $_POST['cities'], 
				'slug' => $slug
			));
	
	//Send email to the user who created this group. Inlude the Group Code that was generated.
	$group_name = $group->name;
	global $bp;
	$group_url = $bp->root_domain."/groups/".$group->slug;  //Create the group url
	global $current_user;
	$to       = $current_user->user_email;
	$subject  = 'Twyne! Your newly created Group Code';
	$message  = "This email contains an important Group Code for the private Group '".$group_name."' that you recently created. The 10-digit code you will need is: ".$group_code."\n\n"
				."In order to add members to ".$group_name.":\n"
				."  1. Send them the code mentioned above \n"
				."  2. Have them visit Twyne.com \n"
				."  3. On the Twyne Homepage, click the image under the label 'Connect through your organizaiton'. This will bring up a dialog box where they will enter the Group Code and redirect them to the Group '".$group_name."'.\n\n"
				."IMPORTANT: Anyone with this Group Code can join '".$group_name."' so it is important that this code is not revealed to people who you do not want in your Group. As the Group administrator, you have the ability to add and remove members. To do so, when logged in to Twyne, simply visit your Group and click on the 'Admin' tab to adjust any of the Group's settings. \n\n"
				."Your Group '".$group_name."' can  be found at ".$group_url;
	$headers  = 'From: twyne@gmail.com' . "\r\n" .
				'Reply-To: twyne@gmail.com' . "\r\n" .
				'MIME-Version: 1.0' . "\r\n" .
				'Content-type: text; charset=iso-8859-1' . "\r\n" .
				'X-Mailer: PHP/' . phpversion();
	mail($to, $subject, $message, $headers);
			
	//If the newly created group never made it through all of the creation steps, the group will be set
	// to public. Update the newly created group to ensure it is set to Private
	$wpdb->query(
			"
			UPDATE {$wpdb->prefix}bp_groups
			SET status = 'private'
			WHERE ID = $id
			"
		); 
}

/* This function is called upon proceeding with the "Next" button on the Group 
 * Creation "Settings" screen. It checks to see if the radio button "Official" was 
 * checked. If so, the creator of the Group wants their group to be official
 * so send us an email with the Group info.
-------------------------------------------------------------*/
add_action('groups_update_group', 'group_creation_official_request', 10, 2);  //priority=10, args=2
function group_creation_official_request($group_id, $group){

	/**
	 *  Values of the object $group:
	 *	'group_id'
	 *	'creator_id'
	 *	'name'
	 *	'description'
	 *	'slug'
	 *	'status'
	 *	'enable_forum'
	 *	'date_created'
	 */
	
	if( 'official' == $_POST['official-group']) {
		$creator_id = $group->creator_id;
		$name = $group->name;
		$description = $group->description;
		$slug = $group->slug;
		
		$to       = 'jmattiace89@gmail.com';
		$subject  = 'Test Email from Twyne';
		$message  = "The Group ID of the newly created group is ". $group_id."\r\n".
					"Creator ID = ".$creator_id."\r\n".
					'Group name = '.$name.'\r\n'.
					'Group slug = '.$slug.'\r\n'.
					'Group description = '.$description;
		$headers  = 'From: jmattiace89@gmail.com' . "\r\n" .
					'Reply-To: jmattiace89@gmail.com' . "\r\n" .
					'MIME-Version: 1.0' . "\r\n" .
					'Content-type: text; charset=iso-8859-1' . "\r\n" .
					'X-Mailer: PHP/' . phpversion();
		mail($to, $subject, $message, $headers);
	}
}

/* This function adds 2 tabs to the Groups subnav options.
 * The 2 tabs are Housing, and Recreation. Additionally, the 'Members'
 * tab is moved to the a different position. The function
 * bp_core_new_subnav_item() is called which does all of the work.
-------------------------------------------------------------*/
add_action( 'bp_setup_nav', 'add_group_subnav_items', 100 ); //Priority must be higher than 10
function add_group_subnav_items() {

	// Housing tab
	$tab_array['name'] = 'Housing';	
	$tab_array['link'] =  bp_get_group_permalink().bp_get_current_group_slug().'/housing';	
	$tab_array['slug'] = 'housing';	
	$tab_array['parent_url'] = bp_get_group_permalink().bp_get_current_group_slug();	
	$tab_array['parent_slug'] = bp_get_current_group_slug();	
	$tab_array['css_id'] = 'housing';	
	$tab_array['position'] = 90;	//Move to 2nd position
	$tab_array['user_has_access'] = '1';	
	$tab_array['screen_function'] = 'groups_screen_group_housing';	
	//$bp->bp_options_nav[bp_get_current_group_slug()][90] = $tab_array;
	bp_core_new_subnav_item($tab_array);
	
	// Move the 'Members' tab to the 4th position
	global $bp;
	$bp->bp_options_nav[bp_get_current_group_slug()]['members']['position'] = 110;
	bp_core_remove_subnav_item( bp_get_current_group_slug(), 'send-invites' ); //Remove Send Invites tab
	
}

/* This function adds 1 tab to the Profile subnav options.
 * The tab is Settings and simply redirects to the existing
 * Settings screen. Additionally, the name of the 'Change Avatar'
 * tab is changed to 'Change Picture'.
-------------------------------------------------------------*/
add_action( 'bp_setup_nav', 'add_profile_subnav_items', 100 ); //Priority must be higher than 10
function add_profile_subnav_items() {
	global $bp;
	
	// Settings tab
	$tab_array['name'] = 'Settings';	
	$tab_array['link'] =  $bp->displayed_user->domain.'settings';	
	$tab_array['slug'] = 'settings';	
	$tab_array['parent_url'] = $bp->displayed_user->domain;	
	$tab_array['parent_slug'] = bp_core_get_userlink(bp_loggedin_user_id());	
	$tab_array['css_id'] = 'settings';	
	$tab_array['position'] = 90;	
	$tab_array['user_has_access'] = '1';	
	$tab_array['screen_function'] = 'bp_settings_screen_general';	
	$bp->bp_options_nav['profile']['settings'] = $tab_array;  //Add new array element to the 'profile' array

	// Change the name of the tab 'Change Avatar' to 'Change Picture'
	$bp->bp_options_nav['profile']['change-avatar']['name'] = 'Change Picture';
		
}

/* The following 2 functions handle the screens that are to be shown 
 * when the either of the 2 custom subnav tabs are clicked: Housing,
 * Recreation. The title of each function is specified in the 'screen_function'
 * attribute when each subnav tab was created in the add_group_nav_items() function.
 * More functionality can be added to these function. For an example, refer to 
 * a function within twyne\wp-content\plugins\buddypress\bp-groups\bp-groups-screens.php
-----------------------------------------------------------------------------*/
function groups_screen_group_housing(){
	//add_action( 'bp_template_title', 'my_groups_page_function_to_show_screen_title' );
    //add_action( 'bp_template_content', 'my_groups_page_function_to_show_screen_content' );
	bp_core_load_template( apply_filters( 'groups_template_group_members', 'groups/single/home' ) );
}
function groups_screen_group_recreation(){
	bp_core_load_template( apply_filters( 'groups_template_group_members', 'groups/single/home' ) );
}

/* Customize the names of the tabs that are displayed on the "Create new group" page to:
 *  1. Details, 2. Settings, 3. Group logo
 * Details and Settings already exist in the array $bp->groups->group_creation_steps.
 * We must first delete the existing 'Invites' tab, then change the name of the 
 * 'Avatar' tab to 'Group Logo'.
 * If we want to add additional tabs, add the following two lines to this function:
 * 		$bp->groups->group_creation_steps['group-test']['name'] = 'Test';
 * 		$bp->groups->group_creation_steps['group-test']['position'] = 50;
 * and create the proper screen for it in create.php
-----------------------------------------------------------------------------*/
add_action( 'bp_setup_nav', 'customize_group_creation_tabs', 100 ); //Priority must be higher than 10
function customize_group_creation_tabs(){
	global $bp;
	unset( $bp->groups->group_creation_steps['group-invites']);
	$bp->groups->group_creation_steps['group-avatar']['name'] = 'Group Logo';
}
/*Removes Connect From connects list*/
add_action('wp_ajax_removeConnect', 'removeConnect');
function removeConnect(){
	global $wpdb;
	$id = $_POST["fid"]; 
	$userid = $_POST["uid"]; 
	$wpdb->query( 
			$wpdb->prepare( 
		"
		 DELETE FROM {$wpdb->prefix}bp_friends
				WHERE initiator_user_id = $userid
				AND friend_user_id = $id
		"	
			)
		);
		
		die();
}
/* This function is to customize the subnav tabs that are displayed on 
 * the Admin screen of a group. The code is adapted from bp_group_admin_tabs() 
 * in buddypress/bp-groups/bp-groups-template.php. The changes are:
 * 1. Changed the "Avatar" tab to read "Group Logo"
 * 2. Removed the Group Request tab
 -----------------------------------------------------------------------------*/
 function get_group_admin_tabs() {
	global $bp, $groups_template;

	if ( empty( $group ) )
		$group = ( $groups_template->group ) ? $groups_template->group : $bp->groups->current_group;

	$current_tab = bp_get_group_current_admin_tab();

	if ( bp_is_item_admin() || bp_is_item_mod() ) : ?>
		<li<?php if ( 'edit-details' == $current_tab || empty( $current_tab ) ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( bp_get_group_permalink( $group ) . 'admin/edit-details' ) ?>"><?php _e( 'Details', 'buddypress' ); ?></a></li>
	<?php endif; ?>

	<?php if ( ! bp_is_item_admin() )
			return false; ?>

	<li<?php if ( 'group-settings' == $current_tab ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( bp_get_group_permalink( $group ) . 'admin/group-settings' ) ?>"><?php _e( 'Settings', 'buddypress' ); ?></a></li>

	<?php if ( !(int)bp_get_option( 'bp-disable-avatar-uploads' ) ) : ?>
		<li<?php if ( 'group-avatar'   == $current_tab ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( bp_get_group_permalink( $group ) . 'admin/group-avatar' ) ?>"><?php _e( 'Group Logo', 'buddypress' ); ?></a></li>
	<?php endif; ?>

	<li<?php if ( 'manage-members' == $current_tab ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( bp_get_group_permalink( $group ) . 'admin/manage-members' ) ?>"><?php _e( 'Members', 'buddypress' ); ?></a></li>

	<?php do_action( 'groups_admin_tabs', $current_tab, $group->slug ) ?>

	<li<?php if ( 'delete-group' == $current_tab ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( bp_get_group_permalink( $group ) . 'admin/delete-group' ) ?>"><?php _e( 'Delete', 'buddypress' ); ?></a></li>

<?php
}

/* This function overrides the actions that are performed when do_action('bp_notification_settings)
 * is called to create the notification screen on the settings page in order to 
 * cusomize these settings.
-----------------------------------------------------------------------------*/
function notification_settings_screen(){
	//Activity settings. Calls the function in the core file because no customization is needed for these settings
	bp_activity_screen_notification_settings();
	//Messages settings. Calls the function in the core file because no customization is needed for these settings
	messages_screen_notification_settings();
	//Friends settings
	//friends_screen_notification_settings();
	//Groups settings. Calls the function in the core file because no customization is needed for these settings
	groups_screen_notification_settings();
}
add_action( 'bp_members_notification_settings_before_submit', 'notification_settings_screen', 2 );


?>


<?php
//Sidebar login redirects to homepage
function bp_dtheme_sidebar_login_redirect_to() {
	$redirect_to = get_home_url().'/home';
	$redirect_to = apply_filters( 'bp_no_access_redirect', $redirect_to ); ?>
	<input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" />

<?php
}
add_action( 'bp_sidebar_login_form', 'bp_dtheme_sidebar_login_redirect_to' );
add_action( 'login_form', 'bp_dtheme_sidebar_login_redirect_to' );
?>
<?php
 /*---------------------------------------------------
		EDIT MATCHING ANSWERS
------------------------------------------------------*/
add_action('wp_ajax_editMatches', 'edit_Match');
add_action('wp_ajax_nopriv_editMatches', 'edit_Match');
function edit_Match() {
	global $wpdb;
	$userid = $_POST["userid"];
	$my_ans = $wpdb->get_row("SELECT *
							FROM wp_twyne_matching
							WHERE $userid = user_id",ARRAY_N );
	$sex = $wpdb->get_var($wpdb->prepare("SELECT value
										  FROM wp_bp_xprofile_data
										  WHERE user_id = $userid AND field_id = '3'"));
	$ch1 = ""; $ch2 = "";
	if($my_ans[1] == 1){$ch1 = "checked=\'checked\'";}else{$ch0 = "checked=\'checked\'";}
	print"<form name = 'matchingForm'>	
		<p><u>Co-ED Roommates</u></p>
		<div class='question1'>
	<input type='radio' name='q1' id='q1_button_1' value = '1' $ch1/>
			<label for='q1_button_1'>Yes</label>
		</div>
		<div class='question1'>
			<input type='radio' name='q1' id='q1_button_2' value = '0' $ch0/>
			<label for='q1_button_2'>No</label>
		</div>
		</br></br>";
	$ch  = array();
	for($i = 1; $i <6;$i++){
		if($my_ans[2] == $i){
			$ch[$i-1] = "checked=\'checked\'"; 
		}
	}
	print"<p><u>Cleanliness</u></p>
    <div class='question2'>
        <input type='radio' name='q2' id='q2_button_1' value = '1' $ch[0]/>
		<label for='q2_button_1'>1</label>
    </div>
    <div class='question2'>
        <input type='radio' name='q2' id='q2_button_2' value = '2' $ch[1]/>
		<label for='q2_button_2'>2</label>
    </div>
    <div class='question2'>
        <input type='radio' name='q2' id='q2_button_3'  value = '3' $ch[2]/>
		<label for='q2_button_3'>3</label>
    </div>
	<div class='question2'>
        <input type='radio' name='q2' id='q2_button_4' value = '4' $ch[3]/>
		<label for='q2_button_4'>4</label>
    </div>
	<div class='question2'>
        <input type='radio' name='q2' id='q2_button_5' value = '5' $ch[4]/>
		<label for='q2_button_5'>5</label>
    </div>
	</br></br>";
	$ch  = array();
	for($i = 1; $i <6;$i++){
		if($my_ans[3] == $i){
			$ch[$i-1] = "checked=\'checked\'"; 
		}
	}
	print"<p><u>Quietness</u></p>
    <div class='question3'>
        <input type='radio' name='q3' id='q3_button_1' value = '1' $ch[0]/>
		<label for='q3_button_1'>1</label>
    </div>
    <div class='question3'>
        <input type='radio' name='q3' id='q3_button_2' value = '2' $ch[1]/>
		<label for='q3_button_2'>2</label>
    </div>
    <div class='question3'>
        <input type='radio' name='q3' id='q3_button_3' value = '3' $ch[2]/>
		<label for='q3_button_3'>3</label>
    </div>
	<div class='question3'>
        <input type='radio' name='q3' id='q3_button_4' value = '4' $ch[3]/>
		<label for='q3_button_4'>4</label>
    </div>
	<div class='question3'>
        <input type='radio' name='q3' id='q3_button_5' value = '5' $ch[4]/>
		<label for='q3_button_5'>5</label>
    </div>
	</br></br>";
	$ch  = array();
	for($i = 1; $i <6;$i++){
		if($my_ans[4] == $i){
			$ch[$i-1] = "checked=\'checked\'"; 
		}
	}
	print"<p><u>How often do you Attend Parties</u></p>
    <div class='question4'>
        <input type='radio' name='q4' id='q4_button_1' value = '1' $ch[0]/>
		<label for='q4_button_1'>1</label>
    </div>
    <div class='question4'>
        <input type='radio' name='q4' id='q4_button_2' value = '2' $ch[1]/>
		<label for='q4_button_2'>2</label>
    </div>
    <div class='question4'>
        <input type='radio' name='q4' id='q4_button_3' value = '3' $ch[2]/>
		<label for='q4_button_3'>3</label>
    </div>
	<div class='question4'>
        <input type='radio' name='q4' id='q4_button_4' value = '4' $ch[3]/>
		<label for='q4_button_4'>4</label>
    </div>
	<div class='question4'>
        <input type='radio' name='q4' id='q4_button_5' value = '5' $ch[4]/>
		<label for='q4_button_5'>5</label>
    </div>
	</br>
	</br>";
	$ch  = array();
	for($i = 1; $i <6;$i++){
		if($my_ans[5] == $i){
			$ch[$i-1] = "checked=\'checked\'"; 
		}
	}
	print"<p><u>How often do you Host Parties</u></p>
    <div class='question5'>
        <input type='radio' name='q5' id='q5_button_1' value = '1' $ch[0]/>
		<label for='q5_button_1'>1</label>
    </div>
    <div class='question5'>
        <input type='radio' name='q5' id='q5_button_2' value = '2' $ch[1]/>
		<label for='q5_button_2'>2</label>
    </div>
    <div class='question5'>
        <input type='radio' name='q5' id='q5_button_3' value = '3' $ch[2]/>
		<label for='q5_button_3'>3</label>
    </div>
	<div class='question5'>
        <input type='radio' name='q5' id='q5_button_4' value = '4' $ch[3]/>
		<label for='q5_button_4'>4</label>
    </div>
	<div class='question5'>
        <input type='radio' name='q5' id='q5_button_5' value = '5' $ch[4]/>
		<label for='q5_button_5'>5</label>
    </div>
	</br></br>";
	$ch  = array();
	for($i = 1; $i <6;$i++){
		if($my_ans[6] == $i){
			$ch[$i-1] = "checked=\'checked\'"; 
		}
	}
	print"<p><u>How often do you have friends/family over?</u></p>
    <div class='question6'>
        <input type='radio' name='q6' id='q6_button_1' value = '1' $ch[0]/>
		<label for='q6_button_1'>1</label>
    </div>
    <div class='question6'>
        <input type='radio' name='q6' id='q6_button_2' value = '2' $ch[1]/>
		<label for='q6_button_2'>2</label>
    </div>
    <div class='question6'>
        <input type='radio' name='q6' id='q6_button_3' value = '3' $ch[2]/>
		<label for='q6_button_3'>3</label>
    </div>
	<div class='question6'>
        <input type='radio' name='q6' id='q6_button_4' value = '4' $ch[3]/>
		<label for='q6_button_4'>4</label>
    </div>
	<div class='question6'>
        <input type='radio' name='q6' id='q6_button_5' value = '5' $ch[4]/>
		<label for='q6_button_5'>5</label>
    </div>
	</br></br>";
	$ch  = array();
	for($i = 1; $i <6;$i++){
		if($my_ans[7] == $i){
			$ch[$i-1] = "checked=\'checked\'"; 
		}
	}
	print"<p><u>How often do you Watch TV?</u></p>
    <div class='question7'>
        <input type='radio' name='q7' id='q7_button_1' value = '1' $ch[0]/>
		<label for='q7_button_1'>1</label>
    </div>
    <div class='question7'>
        <input type='radio' name='q7' id='q7_button_2' value = '2' $ch[1]/>
		<label for='q7_button_2'>2</label>
    </div>
    <div class='question7'>
        <input type='radio' name='q7' id='q7_button_3' value = '3' $ch[2]/>
		<label for='q7_button_3'>3</label>
    </div>
	<div class='question7'>
        <input type='radio' name='q7' id='q7_button_4' value = '4' $ch[3]/>
		<label for='q7_button_4'>4</label>
    </div>
	<div class='question7'>
        <input type='radio' name='q7' id='q7_button_5' value = '5' $ch[4]/>
		<label for='q7_button_5'>5</label>
    </div>
	</br></br>";
	$ch  = array();
	for($i = 1; $i <6;$i++){
		if($my_ans[8] == $i){
			$ch[$i-1] = "checked=\'checked\'"; 
		}
	}
	print"<p><u>How often do you play Video Games?</u></p>
    <div class='question8'>
        <input type='radio' name='q8' id='q8_button_1' value = '1' $ch[0]/>
		<label for='q8_button_1'>1</label>
    </div>
    <div class='question8'>
        <input type='radio' name='q8' id='q8_button_2' value = '2' $ch[1]/>
		<label for='q8_button_2'>2</label>
    </div>
    <div class='question8'>
        <input type='radio' name='q8' id='q8_button_3' value = '3' $ch[2]/>
		<label for='q8_button_3'>3</label>
    </div>
	<div class='question8'>
        <input type='radio' name='q8' id='q8_button_4' value = '4' $ch[3]/>
		<label for='q8_button_4'>4</label>
    </div>
	<div class='question8'>
        <input type='radio' name='q8' id='q8_button_5' value = '5' $ch[4]/>
		<label for='q8_button_5'>5</label>
    </div>
	</br></br>";
	$ch  = array();
	for($i = 1; $i <6;$i++){
		if($my_ans[9] == $i){
			$ch[$i-1] = "checked=\'checked\'"; 
		}
	}
	print"<p><u>How often do you Listen to Music?</u></p>
    <div class='question9'>
        <input type='radio' name='q9' id='q9_button_1' value = '1' $ch[0]/>
		<label for='q9_button_1'>1</label>
    </div>
    <div class='question9'>
        <input type='radio' name='q9' id='q9_button_2' value = '2' $ch[1]/>
		<label for='q9_button_2'>2</label>
    </div>
    <div class='question9'>
        <input type='radio' name='q9' id='q9_button_3' value = '3' $ch[2]/>
		<label for='q9_button_3'>3</label>
    </div>
	<div class='question9'>
        <input type='radio' name='q9' id='q9_button_4' value = '4' $ch[3]/>
		<label for='q9_button_4'>4</label>
    </div>
	<div class='question9'>
        <input type='radio' name='q9' id='q9_button_5' value = '5' $ch[4]/>
		<label for='q9_button_5'>5</label>
    </div>
	</br>
	</br>";
	$ch  = array();
	for($i = 1; $i <6;$i++){
		if($my_ans[10] == $i){
			$ch[$i-1] = "checked=\'checked\'"; 
		}
	}
	print"<p><u>How often do you Drink?</u></p>
    <div class='question10'>
        <input type='radio' name='q10' id='q10_button_1' value = '1' $ch[0]/>
		<label for='q10_button_1'>1</label>
    </div>
    <div class='question10'>
        <input type='radio' name='q10' id='q10_button_2' value = '2' $ch[1]/>
		<label for='q10_button_2'>2</label>
    </div>
    <div class='question10'>
        <input type='radio' name='q10' id='q10_button_3' value = '3' $ch[2]/>
		<label for='q10_button_3'>3</label>
    </div>
	<div class='question10'>
        <input type='radio' name='q10' id='q10_button_4' value = '4' $ch[3]/>
		<label for='q10_button_4'>4</label>
    </div>
	<div class='question10'>
        <input type='radio' name='q10' id='q10_button_5' value = '5' $ch[4]/>
		<label for='q10_button_5'>5</label>
    </div>
	</br></br>";
	$ch  = array();
	for($i = 1; $i <6;$i++){
		if($my_ans[11] == $i){
			$ch[$i-1] = "checked=\'checked\'"; 
		}
	}
	print"<p><u>How often do you Smoke?</u></p>
    <div class='question11'>
        <input type='radio' name='q11' id='q11_button_1' value = '1' $ch[0]/>
		<label for='q11_button_1'>1</label>
    </div>
    <div class='question11'>
        <input type='radio' name='q11' id='q11_button_2' value = '2' $ch[1]/>
		<label for='q11_button_2'>2</label>
    </div>
    <div class='question11'>
        <input type='radio' name='q11' id='q11_button_3' value = '3' $ch[2]/>
		<label for='q11_button_3'>3</label>
    </div>
	<div class='question11'>
        <input type='radio' name='q11' id='q11_button_4' value = '4' $ch[3]/>
		<label for='q11_button_4'>4</label>
    </div>
	<div class='question11'>
        <input type='radio' name='q11' id='q11_button_5' value = '5' $ch[4]/>
		<label for='q11_button_5'>5</label>
    </div>
	</br></br>";
	$ch  = array();
	for($i = 1; $i <6;$i++){
		if($my_ans[12] == $i){
			$ch[$i-1] = "checked=\'checked\'"; 
		}
	}
	print"<p><u>How often do you Go Out?</u></p>
    <div class='question12'>
        <input type='radio' name='q12' id='q12_button_1' value = '1' $ch[0]/>
		<label for='q12_button_1'>1</label>
    </div>
    <div class='question12'>
        <input type='radio' name='q12' id='q12_button_2' value = '2' $ch[1]/>
		<label for='q12_button_2'>2</label>
    </div>
    <div class='question12'>
        <input type='radio' name='q12' id='q12_button_3' value = '3' $ch[2]/>
		<label for='q12_button_3'>3</label>
    </div>
	<div class='question12'>
        <input type='radio' name='q12' id='q12_button_4' value = '4' $ch[3]/>
		<label for='q12_button_4'>4</label>
    </div>
	<div class='question12'>
        <input type='radio' name='q12' id='q12_button_5' value = '5' $ch[4]/>
		<label for='q12_button_5'>5</label>
    </div>
	</br></br>";
	$ch  = array();
	for($i = 1; $i <6;$i++){
		if($my_ans[13] == $i){
			$ch[$i-1] = "checked=\'checked\'"; 
		}
	}
	print"<p><u>How often do you go to Bed Late?</u></p>
    <div class='question13'>
        <input type='radio' name='q13' id='q13_button_1' value = '1' $ch[0]/>
		<label for='q13_button_1'>1</label>
    </div>
    <div class='question13'>
        <input type='radio' name='q13' id='q13_button_2' value = '2' $ch[1]/>
		<label for='q13_button_2'>2</label>
    </div>
    <div class='question13'>
        <input type='radio' name='q13' id='q13_button_3' value = '3' $ch[2]/>
		<label for='q13_button_3'>3</label>
    </div>
	<div class='question13'>
        <input type='radio' name='q13' id='q13_button_4' value = '4' $ch[3]/>
		<label for='q13_button_4'>4</label>
    </div>
	<div class='question13'>
        <input type='radio' name='q13' id='q13_button_5' value = '5' $ch[4]/>
		<label for='q13_button_5'>5</label>
    </div>
	</br></br>";
	$ch  = array();
	for($i = 1; $i <6;$i++){
		if($my_ans[14] == $i){
			$ch[$i-1] = "checked=\'checked\'"; 
		}
	}
	print"<p><u>How often do you Sleep In?</u></p>
    <div class='question14'>
        <input type='radio' name='q14' id='q14_button_1' value = '1' $ch[0]/>
		<label for='q14_button_1'>1</label>
    </div>
    <div class='question14'>
        <input type='radio' name='q14' id='q14_button_2' value = '2' $ch[1]/>
		<label for='q14_button_2'>2</label>
    </div>
    <div class='question14'>
        <input type='radio' name='q14' id='q14_button_3' value = '3' $ch[2]/>
		<label for='q14_button_3'>3</label>
    </div>
	<div class='question14'>
        <input type='radio' name='q14' id='q14_button_4' value = '4' $ch[3]/>
		<label for='q14_button_4'>4</label>
    </div>
	<div class='question14'>
        <input type='radio' name='q14' id='q14_button_5' value = '5' $ch[4]/>
		<label for='q14_button_5'>5</label>
    </div>
	</br></br>";
	$ch  = array();
	for($i = 1; $i <6;$i++){
		if($my_ans[15] == $i){
			$ch[$i-1] = "checked=\'checked\'"; 
		}
	}
	print"<p><u>How much time do you Spend in your room?</u></p>
    <div class='question15'>
        <input type='radio' name='q15' id='q15_button_1' value = '1' $ch[0]/>
		<label for='q15_button_1'>1</label>
    </div>
    <div class='question15'>
        <input type='radio' name='q15' id='q15_button_2' value = '2' $ch[1]/>
		<label for='q15_button_2'>2</label>
    </div>
    <div class='question15'>
        <input type='radio' name='q15' id='q15_button_3' value = '3' $ch[2]/>
		<label for='q15_button_3'>3</label>
    </div>
	<div class='question15'>
        <input type='radio' name='q15' id='q15_button_4' value = '4' $ch[3]/>
		<label for='q15_button_4'>4</label>
    </div>
	<div class='question15'>
        <input type='radio' name='q15' id='q15_button_5' value = '5' $ch[4]/>
		<label for='q15_button_5'>5</label>
    </div>
	</br></br>";
	$ch  = array();
	for($i = 1; $i <6;$i++){
		if($my_ans[16] == $i){
			$ch[$i-1] = "checked=\'checked\'"; 
		}
	}
	print"<p><u>How often do you Cook?</u></p>
    <div class='question16'>
        <input type='radio' name='q16' id='q16_button_1' value = '1' $ch[0]/>
		<label for='q16_button_1'>1</label>
    </div>
    <div class='question16'>
        <input type='radio' name='q16' id='q16_button_2' value = '2' $ch[1]/>
		<label for='q16_button_2'>2</label>
    </div>
    <div class='question16'>
        <input type='radio' name='q16' id='q16_button_3' value = '3' $ch[2]/>
		<label for='q16_button_3'>3</label>
    </div>
	<div class='question16'>
        <input type='radio' name='q16' id='q16_button_4' value = '4' $ch[3]/>
		<label for='q16_button_4'>4</label>
    </div>
	<div class='question16'>
        <input type='radio' name='q16' id='q16_button_5' value = '5' $ch[4]/>
		<label for='q16_button_5'>5</label>
    </div>
	</br></br>";
	$ch  = array();
	for($i = 1; $i <6;$i++){
		if($my_ans[17] == $i){
			$ch[$i-1] = "checked=\'checked\'"; 
		}
	}
	print"<p><u>How often do you Eat Out?</u></p>
    <div class='question17'>
        <input type='radio' name='q17' id='q17_button_1' value = '1' $ch[0]/>
		<label for='q17_button_1'>1</label>
    </div>
    <div class='question17'>
        <input type='radio' name='q17' id='q17_button_2' value = '2' $ch[1]/>
		<label for='q17_button_2'>2</label>
    </div>
    <div class='question17'>
        <input type='radio' name='q17' id='q17_button_3' value = '3' $ch[2]/>
		<label for='q17_button_3'>3</label>
    </div>
	<div class='question17'>
        <input type='radio' name='q17' id='q17_button_4' value = '4' $ch[3]/>
		<label for='q4_button_17'>4</label>
    </div>
	<div class='question17'>
        <input type='radio' name='q17' id='q17_button_5' value = '5' $ch[4]/>
		<label for='q17_button_5'>5</label>
    </div>
	</br></br>";
	$ch  = array();
	for($i = 1; $i <6;$i++){
		if($my_ans[18] == $i){
			$ch[$i-1] = "checked=\'checked\'"; 
		}
	}
	print"<p><u>How often do you Work at Home?</u></p>
    <div class='question18'>
        <input type='radio' name='q18' id='q18_button_1' value = '1' $ch[0]/>
		<label for='q18_button_1'>1</label>
    </div>
    <div class='question18'>
        <input type='radio' name='q18' id='q18_button_2' value = '2' $ch[1]/>
		<label for='q18_button_2'>2</label>
    </div>
    <div class='question18'>
        <input type='radio' name='q18' id='q18_button_3' value = '3' $ch[2]/>
		<label for='q18_button_3'>3</label>
    </div>
	<div class='question18'>
        <input type='radio' name='q18' id='q18_button_4' value = '4' $ch[3]/>
		<label for='q18_button_4'>4</label>
    </div>
	<div class='question18'>
        <input type='radio' name='q18' id='q18_button_5' value = '5' $ch[4]/>
		<label for='q18_button_5'>5</label>
    </div>
	</br></br>";
	$ch  = array();
	for($i = 1; $i <6;$i++){
		if($my_ans[20] == $i){
			$ch[$i-1] = "checked=\'checked\'"; 
		}
	}
	print"<p><u>How often do you Study?</u></p>
    <div class='question19'>
        <input type='radio' name='q19' id='q19_button_1' value = '1' $ch[0]/>
		<label for='q19_button_1'>1</label>
    </div>
    <div class='question19'>
        <input type='radio' name='q19' id='q19_button_2' value = '2' $ch[1]/>
		<label for='q19_button_2'>2</label>
    </div>
    <div class='question19'>
        <input type='radio' name='q19' id='q19_button_3' value = '3' $ch[2]/>
		<label for='q19_button_3'>3</label>
    </div>
	<div class='question19'>
        <input type='radio' name='q19' id='q19_button_4' value = '4' $ch[3]/>
		<label for='q19_button_4'>4</label>
    </div>
	<div class='question19'>
        <input type='radio' name='q19' id='q19_button_5' value = '5' $ch[4]/>
		<label for='q19_button_5'>5</label>
    </div>
	</br></br>";
	$ch  = array();
	for($i = 1; $i <6;$i++){
		if($my_ans[20] == $i){
			$ch[$i-1] = "checked=\'checked\'"; 
		}
	}
	print"<p><u>How often do you Travel?</u></p>
    <div class='question20'>
        <input type='radio' name='q20' id='q20_button_1' value = '1'/ $ch[0]>
		<label for='q20_button_1'>1</label>
    </div>
    <div class='question20'>
        <input type='radio' name='q20' id='q20_button_2' value = '2'/ $ch[1]>
		<label for='q20_button_2'>2</label>
    </div>
    <div class='question20'>
        <input type='radio' name='q20' id='q20_button_3' value = '3'/ $ch[2]>
		<label for='q20_button_3'>3</label>
    </div>
	<div class='question20'>
        <input type='radio' name='q20' id='q20_button_4' value = '4'/ $ch[3]>
		<label for='q20_button_4'>4</label>
    </div>
	<div class='question20'> 
        <input type='radio' name='q20' id='q20_button_5' value = '5'/ $ch[4]>
		<label for='q20_button_5'>5</label>
    </div>
	</br></br>";
	$ch  = array();
	for($i = 1; $i <6;$i++){
		if($my_ans[21] == $i){
			$ch[$i-1] = "checked=\'checked\'"; 
		}
	}
	print"<p><u>How often do you Workout</u></p>
    <div class='question21'>
        <input type='radio' name='q21' id='q21_button_1' value = '1' $ch[0]/>
		<label for='q21_button_1'>1</label>
    </div>
    <div class='question21'>
        <input type='radio' name='q21' id='q21_button_2' value = '2' $ch[1]/>
		<label for='q21_button_2'>2</label>
    </div>
    <div class='question21'>
        <input type='radio' name='q21' id='q21_button_3' value = '3' $ch[2]/>
		<label for='q21_button_3'>3</label>
    </div>
	<div class='question21'>
        <input type='radio' name='q21' id='q21_button_4' value = '4' $ch[3]/>
		<label for='q21_button_4'>4</label>
    </div>
	<div class='question21'>
        <input type='radio' name='q21' id='q21_button_5' value = '5' $ch[4]/>
		<label for='q21_button_5'>5</label>
    </div>
	</br></br>";
	$ch  = array();
	for($i = 1; $i <6;$i++){
		if($my_ans[22] == $i){
			$ch[$i-1] = "checked=\'checked\'"; 
		}
	}
	print"<p><u>Organized</u></p>
    <div class='question22'>
        <input type='radio' name='q22' id='q22_button_1' value = '1' $ch[0]/>
		<label for='q22_button_1'>1</label>
    </div>
    <div class='question22'>
        <input type='radio' name='q22' id='q22_button_2' value = '2' $ch[1]/>
		<label for='q22_button_2'>2</label>
    </div>
    <div class='question22'>
        <input type='radio' name='q22' id='q22_button_3' value = '3' $ch[2]/>
		<label for='q22_button_3'>3</label>
    </div>
	<div class='question22'>
        <input type='radio' name='q22' id='q22_button_4' value = '4' $ch[3]/>
		<label for='q22_button_4'>4</label>
    </div>
	<div class='question22'>
        <input type='radio' name='q22' id='q22_button_5' value = '5' $ch[4]/>
		<label for='q22_button_5'>5</label>
    </div>
	</br></br>";
	$ch  = array();
	for($i = 1; $i <6;$i++){
		if($my_ans[23] == $i){
			$ch[$i-1] = "checked=\'checked\'"; 
		}
	}
	print"<p><u>Outgoing</u></p>
    <div class='question23'>
        <input type='radio' name='q23' id='q23_button_1' value = '1' $ch[0]/>
		<label for='q23_button_1'>1</label>
    </div>
    <div class='question23'>
        <input type='radio' name='q23' id='q23_button_2' value = '2' $ch[1]/>
		<label for='q23_button_2'>2</label>
    </div>
    <div class='question23'>
        <input type='radio' name='q23' id='q23_button_3' value = '3' $ch[2]/>
		<label for='q23_button_3'>3</label>
    </div>
	<div class='question23'>
        <input type='radio' name='q23' id='q23_button_4' value = '4' $ch[3]/>
		<label for='q23_button_4'>4</label>
    </div>
	<div class='question23'>
        <input type='radio' name='q23' id='q23_button_5' value = '5' $ch[4]/>
		<label for='q23_button_5'>5</label>
    </div>
	</br></br>";
	$ch  = array();
	for($i = 1; $i <6;$i++){
		if($my_ans[24] == $i){
			$ch[$i-1] = "checked=\'checked\'"; 
		}
	}
	print"<p><u>Logical</u></p>
    <div class='question24'>
        <input type='radio' name='q24' id='q24_button_1' value = '1' $ch[0]/>
		<label for='q24_button_1'>1</label>
    </div>
    <div class='question24'>
        <input type='radio' name='q24' id='q24_button_2' value = '2' $ch[1]/>
		<label for='q24_button_2'>2</label>
    </div>
    <div class='question24'>
        <input type='radio' name='q24' id='q24_button_3' value = '3' $ch[2]/>
		<label for='q24_button_3'>3</label>
    </div>
	<div class='question24'>
        <input type='radio' name='q24' id='q24_button_4' value = '4' $ch[3]/>
		<label for='q24_button_4'>4</label>
    </div>
	<div class='question24'>
        <input type='radio' name='q24' id='q24_button_5' value = '5' $ch[4]/>
		<label for='q24_button_5'>5</label>
    </div>
	</br></br>";
	$ch  = array();
	for($i = 1; $i <6;$i++){
		if($my_ans[25] == $i){
			$ch[$i-1] = "checked=\'checked\'"; 
		}
	}
	print"<p><u>Artistic</u></p>
    <div class='question25'>
        <input type='radio' name='q25' id='q25_button_1' value = '1' $ch[0]/>
		<label for='q25_button_1'>1</label>
    </div>
    <div class='question25'>
        <input type='radio' name='q25' id='q25_button_2' value = '2' $ch[1]/>
		<label for='q25_button_2'>2</label>
    </div>
    <div class='question25'>
        <input type='radio' name='q25' id='q25_button_3' value = '3' $ch[2]/>
		<label for='q25_button_3'>3</label>
    </div>
	<div class='question25'>
        <input type='radio' name='q25' id='q25_button_4' value = '4' $ch[3]/>
		<label for='q25_button_4'>4</label>
    </div>
	<div class='question25'>
        <input type='radio' name='q25' id='q25_button_5' value = '5' $ch[4]/>
		<label for='q25_button_5'>5</label>
    </div>
	</br></br>";
	$ch  = array();
	for($i = 1; $i <6;$i++){
		if($my_ans[26] == $i){
			$ch[$i-1] = "checked=\'checked\'"; 
		}
	}
	print"<p><u>Decisive</u></p>
    <div class='question26'>
        <input type='radio' name='q26' id='q26_button_1' value = '1' $ch[0]/>
		<label for='q26_button_1'>1</label>
    </div>
    <div class='question26'>
        <input type='radio' name='q26' id='q26_button_2' value = '2' $ch[1]/>
		<label for='q26_button_2'>2</label>
    </div>
    <div class='question26'>
        <input type='radio' name='q26' id='q26_button_3' value = '3' $ch[2]/>
		<label for='q26_button_26'>3</label>
    </div>
	<div class='question26'>
        <input type='radio' name='q26' id='q26_button_4' value = '4' $ch[3]/>
		<label for='q26_button_4'>4</label>
    </div>
	<div class='question26'>
        <input type='radio' name='q26' id='q26_button_5' value = '5' $ch[4]/>
		<label for='q26_button_5'>5</label>
    </div>
	</br></br>";

	 print"<input type='Submit' value = 'Submit!' onClick = doMatch('$userid');>";
	
	echo"</form>";	
	die();
}
/* These functions are to customize the login page 
 -----------------------------------------------------------------------------*/
function my_login_logo() { ?>
    <style type="text/css">
		body.login {
			background: #EE7600;
			min-width: 0;
		}
		.login form {
			margin-left: 8px;
			padding: 26px 24px 46px;
			font-weight: normal;
			background: #008BB3;
			border: 1px solid #E5E5E5;
			-moz-box-shadow: rgba(200,200,200,0.7) 0 4px 10px -1px;
			-webkit-box-shadow: rgba(200, 200, 200, 0.7) 0 4px 10px -1px;
			box-shadow: rgba(200, 200, 200, 0.7) 0 4px 10px -1px;
		}
        body.login div#login h1 a {
            background-image: url(<?php echo get_bloginfo( 'stylesheet_directory' ) ?>/graphics/Logo.png);
            padding-bottom: 0px;
        }
		.login label {
			color: white;
			font-size: 18px;
		}
		input.button-primary, button.button-primary, a.button-primary {
			border-color: #AFA88F;
			font-weight: bold;
			color: #F8F8F8;
			background: #F0F3F5 url(<?php echo get_bloginfo( 'stylesheet_directory' ) ?>/graphics/button-grad.png) repeat-x scroll left top;
		}
		.login #nav a, .login #backtoblog a {
			color: white!important;
			font-size: 16;
		}
    </style>
<?php }
add_action( 'login_enqueue_scripts', 'my_login_logo' );

function my_login_logo_url() {
    return get_bloginfo( 'url' );
}
add_filter( 'login_headerurl', 'my_login_logo_url' );

function my_login_logo_url_title() {
    return 'Twyne';
}
add_filter( 'login_headertitle', 'my_login_logo_url_title' );

?>
